
import java.io.IOException;
import java.util.ArrayList;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import webpage.CreateDBConnection;

/**
 * Servlet implementation class Login
 */
@WebServlet(description = "verify login credentials", urlPatterns = { "/Login.do" })
public class Login extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
	ArrayList<String>details = new ArrayList<String>();
	
    public Login() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String loginEmail = request.getParameter("loginEmail");
		String password = request.getParameter("password");
		System.out.println(loginEmail);
		CreateDBConnection create = new CreateDBConnection();
		boolean result = create.verifyLogin(loginEmail, password);
		if (result == true) {
			details = create.getDetails(loginEmail);
			HttpSession session = request.getSession(true);
			session.setAttribute("details", details);
			session.setAttribute("loginEmail", loginEmail);
			System.out.println(details.get(2));
			RequestDispatcher rd;
			rd= request.getRequestDispatcher("Profile.jsp");
			rd.forward(request,response);

		} else {
			response.sendRedirect("Login.jsp");
		}
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

}
